package two.chapter_1.c1_1;

import edu.princeton.cs.algs4.StdOut;

public class Ex1_1_14 {


    public static void main(String[] args) {

        StdOut.println(lg(17));
        StdOut.println("mylog:"+mylg(16));

    }


    private static int mylg(int N){
        int i=0;
        while (N>0){
            N=N/2;
            i++;
        }
        //最后一次i多加了所以要减1
        i--;
        return i;
    }



    private static int lg(int n) {
        int shiftRightCount = 0;
        do {
            n >>= 1;
            shiftRightCount++;
        } while (n != 0);
        return shiftRightCount - 1;
    }


}
